<?php
$themename = "iGoogler";
$shortname = "iGoogler_";
$version = "1.0.3";
$options = array (
array("id" => "friendlink_display","title" =>"仅首页显示友情链接", "type" => "checkbox", "std" => "false", "description" => "选择是，请不要在小工具中添加友情链接，主题自动仅在首页添加链接"),
array("id" => "sch_btn_name", "title"=>"搜索按钮名称","type"=>"text","std" => "手气不错","description"=>"主搜索按钮的名称"),
array("id" => "homepage_keywords","title"=>"首页自动高亮关键字(空格分割)","type"=>"text","std" => "wordpress 博客","class"=>"regular-text", "description" =>"首页自动高亮现实的关键字" ),
array("id" => "seach_keywords","title"=>"搜索提示关键字(空格分割)","type"=>"text","std" => "主题 插件","class"=>"regular-text","description" => "搜索框下提示栏自动提示的关键词，建议2个"),
array("id" => "excerpt_first_p","title"=>"自动选取第一段作为摘要","type"=>"checkbox", "std" => "true", "description" => "选择是则自动摘取第一段作为摘要，否则摘取全文的字数"),
array("id" => "excerpt_length","title"=>"摘要最大长度","type"=>"text", "std" => "200", "description"=>"最大的摘要长度"),
array("id" => "sina","title"=>"新浪微博ID","type"=>"text","std" => ""),
array("id" => "tencent","title"=>"腾讯微博ID","type"=>"text","std" => ""),
array("id" => "single_copyright","title"=>"是否显示版权提示","type"=>"checkbox","std" => "true","description"=>"选中后，文章页面会显示版权提示"),
array("id" => "copyright_content","title"=>"版权提示内容","type"=>"textarea","std" => "","description"=>"您可以留空该选项，此时显示默认效果"),
array("id" => "site_stat","title"=>"网站统计代码","type"=>"textarea","std" => "","description"=>"如果您需要，可以在这个位置添加网站统计代码，例如Google Analytics或百度统计"),
array("id" => "h3","title"=>"自定义Logo设置","type"=>"h3"),
array("id" => "navi_left","title"=>"分页图片第一部分宽度","type"=>"text","std" => "46","description"=>"px"),
array("id" => "navi_middle","title"=>"分页图片第二部分宽度","type"=>"text","std" => "20","description"=>"px"),
array("id" => "navi_right","title"=>"分页图片第三部分宽度","type"=>"text","std" => "57","description"=>"px"),
);

function igoogler_admin_panel() {
	global $themename, $shortname, $options;
	if ( $_GET['page'] == basename(__FILE__) ) {
		if ( 'save' == $_REQUEST['action'] ) {
			foreach ($options as $value) {
				update_option( $shortname.$value['id'], $_REQUEST[ $value['id'] ] ); }
				foreach ($options as $value) {
					if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
					header("Location: themes.php?page=func_panel.php&saved=true");
					die;
		} else if( 'reset' == $_REQUEST['action'] ) {
			foreach ($options as $value) {
				update_option( $shortname.$value['id'], $value['std'] );
			}
			header("Location: themes.php?page=func_panel.php&reset=true");
			die;
		}
	}
	add_theme_page($themename." Options", '<span style="color:red">iGoogler设置</span>', 'edit_themes', basename(__FILE__), 'igoogler_admin');
}
function igoogler_admin() {
	global $themename, $shortname, $options, $version;
	if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' 设置已保存。</strong></p></div>';
	if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' 设置已重置。</strong></p></div>';
	?>
<div class="wrap">
<div id="icon-options-general" class="icon32"><br>
</div>
<h2>iGoogler 主题设置</h2>
<form method="post"><input type="hidden" name="action" value="save" />
<?php $version_new = file_get_contents("http://zyj.me/iGoogler.txt"); if($version_new != $version):?>
<div id="message" class="updated fade"><p>当前有版本更新可用，最新版本为<strong><?php echo $version_new;?></strong>，您所用的版本为<?php echo $version;?>。请访问<a href="http://zyj.me/wordpress-theme/igoogler">iGoogler</a>了解详情，并访问<a href="http://zyj.me/wordpress-theme/igoogler">Google Code</a>下载更新。</p></div>
<?php endif?>
<?php if (!function_exists('get_most_viewed')):?>
<div id="message" class="updated fade"><p>您尚未安装<span style="color:red">WP-PostViews</span>插件，WP-PostViews可以直观的帮助您了解每篇日志的访问量，为了您更好体验主题，建议您<a href="http://wordpress.org/extend/plugins/wp-postviews/">点击这儿</a>安装。</p></div>
<?php endif?>
<h3>常规设置</h3>
<table class="form-table">
	<tbody>
	<?php foreach ($options as $value):?>
		<tr>
			<th scope="row">
			<?php if($value['type'] == "h3"): ?>
            <h3><?php echo $value['title'];?></h3>
			<?php else:?>
			<?php echo $value['title']?>
            <?php endif;?></th>
			<td>
            <?php if($value['type'] == "h3"): ?>
            <?php elseif ($value['type'] == "checkbox"):?>
            <input type="<?php echo $value['type']?>" name="<?php echo $value['id'];?>" id="<?php echo $value['id']?>" <?php if(get_option($shortname.$value['id'],$value['std'])==true)echo 'checked="true"';?> />
            <?php elseif ($value['type'] == "textarea"):?>
            <textarea name="<?php echo $value['id'];?>" id="<?php echo $value['id'];?>" class="large-text code"><?php echo stripslashes(get_option($shortname.$value['id'],$value['std']));?></textarea><br />
            <?php else:?>
            <input type="<?php echo $value['type']?>" name="<?php echo $value['id'];?>" id="<?php echo $value['id']?>" value="<?php echo get_option($shortname.$value['id'],$value['std']);?>" />
			<?php endif;?>
			<span class="description"><?php echo $value['description']?></span></td>
		</tr>
		<?php endforeach;?>
	</tbody>
</table>
<h3>如果您在使用主题中遇到问题，请 <a href="mailto:willings.zhang@gmail.com"><strong>点击这儿</strong></a>
反馈Bug</h3>
<p class="submit"><input type="submit" class="button-primary"
	value="保存更改" /></p>
</form>
</div>
		<?php
}
add_action('admin_menu', 'igoogler_admin_panel');
?>